package com.threaddemo2;

public class DeadLock {
    public static void main(String[] args) {
        Object lockA = new Object();
        Object lockB = new Object();

        //1、线程A拿到锁lock 不释放
        //2、线程B要去拿lock 拿不到

        Thread t1 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("进入线程t1");
                synchronized (lockA){
                    System.out.println("线程t1拿到锁A");
                    synchronized (lockB){
                        System.out.println("线程t1拿到锁B");
                    }
                }
            }
        });
        Thread t2 = new Thread(new Runnable() {
            @Override
            public void run() {
                System.out.println("进入线程t2");
                synchronized (lockB){
                    System.out.println("线程t2拿到锁B");
                    synchronized (lockA){
                        System.out.println("线程t2拿到锁A");
                    }
                }
            }
        });

        t1.start();
        t2.start();

    }
}
